<?php
namespace app\index\controller;
use think\Controller;
use app\admin\model\Wenjuan as WenjuanModel;
use app\common\service\PchartService;

class Index extends Controller
{


    public function hello()
    {
       
    }
	
	public function pdf()
    {
		//$a_id = $this->request->param('a_id', 0, 'intval');
        $a_ids = $this->request->param('a_id');
        $a_id_attr = explode('_',$a_ids);
        if ($a_id_attr && count($a_id_attr)==2) {
			$a_id = $a_id_attr[0];
            $create_time = $a_id_attr[1];
            $list = WenjuanModel::where('a_id', '=', $a_id)->where('create_time',$create_time)->find();
			
            if(empty($list['result_josn'])){
                $this->error('报告未生成');
			}
			$list['result_josn'] = json_decode($list['result_josn'],true);
			
			$list['score2'] = 100 - $list['score'];
			$this->assign('list', $list);
			$kechuang = json_decode($list['kechuang'],true);
			$this->assign('kechuang', $kechuang);

			$line_pic = PchartService::makeLine($list);
			$this->assign('line_pic', $line_pic);

			$pie_pic = PchartService::makepie($list);
			$this->assign('pie_pic', $pie_pic);
				
			
			
			//直接显示html项目
			//return $this->fetch('pdf');

			//生成pdf
			$mpdf = new \Mpdf\Mpdf([
				'mode' => 'utf-8',
				'format' => 'A4',
				// 'default_font_size' => 10,
				//'default_font' => 'gb',
				//'defaultCss'=>'p{line-height:4px}'
			]);
			//自动分页符
			$mpdf->autoPageBreak = true;
			//$mpdf->showImageErrors = true; //显示图片错误
			//$mpdf->SetHTMLHeader('页头');
			//$mpdf->SetHTMLFooter('页脚');
			$mpdf->SetDisplayMode('fullpage');
			$mpdf->autoScriptToLang = true; //这几个配置加上可以显示中文
			$mpdf->autoLangToFont = true;//这几个配置加上可以显示中文
			$mpdf->autoArabic = true; //这几个配置加上可以显示中文
			$mpdf->autoVietnamese =true;//这几个配置加上可以显示中文
			
			
			$html = $this->view->fetch('pdf');
			$stylesheet = file_get_contents('./css/pdf.css');
			$mpdf->curlAllowUnsafeSslRequests = true;
			$mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
			$mpdf->WriteHTML($html, \Mpdf\HTMLParserMode::HTML_BODY);
			//$mpdf->Output($a_ids.'.pdf', 'D');
				$mpdf->Output('企业创新量化测评暨科创板、创业板上市和股权融资创新达标测评初评报告.pdf', 'D');
				

        } else {
            $this->error('参数错误');
        }
	
    }
}
